//
//  huisuViewController.m
//  PASystem
//
//  Created by michael on 16/8/28.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "huisuViewController.h"
#import "InternationalMediationController.h"
#import "TrademarkController.h"
#import "ArbitrationController.h"
#import "ExhibitionProjectController.h"
@interface huisuViewController ()

@end

@implementation huisuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.title =@"会属单位管理";
    _array = [NSMutableArray array];

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];

 NSString *json =[NSString stringWithFormat: @"{'action':'getJurisdiction','service':'UserService', 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,name:会属单位管理}'}",userId,pwdId,userHumber];
     NSArray * array = @[@{@"arg0":json}];

     [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
     NSArray *array0 = JSON[@"reason"];
     NSDictionary *dic = [array0 firstObject];
    NSArray *array = dic[@"value"];
    for (NSDictionary *dic in array) {
    NSString *string = dic [@"name"];
    [_array addObject:string];
}
         [self _button];
         NSLog(@"%@",JSON);
         
         

    } failure:^(NSError *error) {
        
    }];

//    _array = @[@"国际展览公司",@"时代公司事务所",@"调解中心",@"全方商标事务所",@"仲裁浙江委员会"];
//创建按钮
     [self _button];

    // Do any additional setup after loading the view.
}
- (void)_button{
    float width = (kScreenWidth-90)/2.0;
    float height = (KScreenHeight-200-46)/4.0;
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc]init];
    flowlayout.itemSize = CGSizeMake(width, height);
       flowlayout.sectionInset = UIEdgeInsetsMake(40, 30, 40, 30);

    flowlayout.minimumInteritemSpacing = 20;
    flowlayout.minimumLineSpacing = 40;
 _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) collectionViewLayout:flowlayout];
  _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.backgroundView = nil;
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellid"];

    [self.view addSubview:_collectionView];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    static NSString * CellIdentifier = @"GradientCell";  

    UICollectionViewCell * cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
    UIImageView *image = [[UIImageView alloc]initWithFrame:cell.contentView.frame];
    image.image = [UIImage imageNamed:_array[indexPath.row]];
    [cell.contentView addSubview:image];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    _array = @[@"国际展览公司",@"时代公司事务所",@"调解中心",@"全放商标事务所",@"仲裁浙江委员会"];

NSString *str = _array[indexPath.row];
NSLog(@"%@",str);
if ([_array[indexPath.row] isEqualToString:@"调解中心"]) {
        InternationalMediationController *inVC = [[InternationalMediationController alloc] init];
    inVC.service = @"HsdwService";
inVC.string = _array[indexPath.row];
        [self.navigationController pushViewController:inVC animated:YES];
        
    }else if ([_array[indexPath.row] isEqualToString:@"全方商标事务所"]){
        TrademarkController *tra = [[TrademarkController alloc] init];
    tra.service = @"HsdwService";
    tra.string = _array[indexPath.row];

        [self.navigationController pushViewController:tra animated:YES];
    
    }else if ([_array[indexPath.row] isEqualToString:@"仲裁浙江委员会"]){
    
        ArbitrationController *arVC = [[ArbitrationController alloc] init];
        arVC.string = _array[indexPath.row];

        arVC.service = @"HsdwService";
        [self.navigationController pushViewController:arVC animated:YES];
    
    }
    else if ([str isEqualToString:@"国际展览公司"]){
    
        ExhibitionProjectController *exVC = [[ExhibitionProjectController alloc] init];
                exVC.service = @"HsdwService";
exVC.string = str;
        exVC.type = ExhibtionCom;
        
        [self.navigationController pushViewController:exVC animated:YES];
    
    }else if ([str isEqualToString:@"时代公司"]){
        
        ExhibitionProjectController *exVC = [[ExhibitionProjectController alloc] init];
        exVC.string = str;
        exVC.service = @"HsdwService";
        exVC.type = TimeCom;
        [self.navigationController pushViewController:exVC animated:YES];
        
    }

}
//展览部
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
